package com.javabi.htmlbuilder.html;

import com.javabi.htmlbuilder.css.CSSDeclarationSet;

/**
 * An HTML Inline Style (also includes id and class attributes).
 */
public class HTMLInlineStyle {

	/** The id. */
	private String id = null;
	/** The class. */
	private String clazz = null;
	/** The style. */
	private CSSDeclarationSet style = null;

	/**
	 * Returns the id
	 * @return the id
	 */
	public final String getId() {
		return id;
	}

	/**
	 * Returns the style.
	 * @return the style.
	 */
	public final CSSDeclarationSet declarations() {
		if (style == null) {
			style = new CSSDeclarationSet();
		}
		// ESCA-JAVA0259: allow return of raw set, not thread safe
		return style;
	}

	/**
	 * Sets the id
	 * @param id the id to set
	 */
	public final void setId(String id) {
		this.id = id;
	}

	/**
	 * Returns the class
	 * @return the class
	 */
	public final String getClazz() {
		return clazz;
	}

	/**
	 * Sets the class
	 * @param clazz the class to set
	 */
	public final void setClazz(String clazz) {
		this.clazz = clazz;
	}

	/**
	 * Append attributes to the given html builder.
	 * @param html the html builder.
	 * @return the html builder.
	 */
	public HTMLBuilder appendAttributesTo(HTMLBuilder html) {
		if (id != null) {
			html.attribute("id", id);
		}
		if (clazz != null) {
			html.attribute("class", clazz);
		}
		if (style != null && !style.isEmpty()) {
			html.attribute("style", style);
		}
		return html;
	}

}
